﻿namespace PortableRiotGames.Infrastructure.Converters
{
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using PortableRiotGames.Interfaces.Team;
    using System;
    using System.Collections.Generic;

    public class JsonGetTeamsResponseConverter : JsonConverter
    {
        public override bool CanConvert(Type objectType)
        {
            throw new NotImplementedException();
        }

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var response = new GetTeamsResponse() { Teams = new List<GetTeamsResponseTeam>() };

            foreach (var token in JArray.Load(reader))
            {
                var team = token.ToObject<GetTeamsResponseTeam>();
                response.Teams.Add(team);
            }

            return response;
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }
    }
}
